<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 
class Main extends CI_Controller {
 
   function __construct()
    {
        parent::__construct();
 
        /* Standard Libraries of codeigniter are required */
        $this->load->database();
        $this->load->helper('url');
        $this->load->library('ion_auth');
		$this->load->library('session');
		$this->load->library('form_validation');
		$this->load->helper('url');
        /* ------------------ */ 
 
        $this->load->library('grocery_CRUD');
 
    }
 
    public function index()
    {
        if (!$this->ion_auth->logged_in() || !$this->ion_auth->is_admin())
        {
                redirect('auth', 'refresh');
        }
        else
        {
             $this->load->view('index.php'); 
        }
       
    }
 
    public function membre()
    {
        $this->grocery_crud->set_table('membre');
        $this->grocery_crud->columns('civilite','nom','prenom','email','adresse1','adresse2','codepostal','ville','pays','fixe','mobile');
        $this->grocery_crud->fields('civilite','nom','prenom','email','adresse1','adresse2','codepostal','ville','pays','fixe','mobile','datenaissance');
        $output = $this->grocery_crud->render();
        $this->_example_output($output);  
    }
    
    public function partenaire()
    {
        $this->grocery_crud->set_table('partenaire');
        $this->grocery_crud->display_as('type_partenaire_id','Type Partenaire');
        $this->grocery_crud->set_subject('partenaire');
  
        $this->grocery_crud->set_relation('type_partenaire_id','type_partenaire','libelle_type');
        $this->grocery_crud->columns('type_partenaire_id','societe','siret','tva','adresse1','adresse2','telephone','fax','codepostal','ville','pays','email');
        //$this->grocery_crud->fields('societe','siret','tva','adresse1','adresse2','telephone','fax','codepostal','ville','pays','email');
        
        $output = $this->grocery_crud->render();
	$this->_example_output($output);       

    }
    public function soin(){
	$this->grocery_crud->set_table('soin');
         $this->grocery_crud->display_as('media_id','Media');
        $this->grocery_crud->set_subject('soin');
  
        $this->grocery_crud->set_relation('media_id','media','lien_url');
        
        $output = $this->grocery_crud->render();
	$this->_example_output($output);       
    }
	
    public function privilege(){
	$this->grocery_crud->set_table('privilege');
        $output = $this->grocery_crud->render();
	$this->_example_output($output);       
    }
	
    public function media(){
	$this->grocery_crud->set_table('media');
        $this->grocery_crud->set_field_upload('lien_url','assets/uploads/files');
        $output = $this->grocery_crud->render();
	$this->_example_output($output);       
    }
	
    public function email(){
	$this->grocery_crud->set_table('email');
        $output = $this->grocery_crud->render();
	$this->_example_output($output);       
	}
	
    public function equipement(){
	$this->grocery_crud->set_table('equipement');
        $output = $this->grocery_crud->render();
	$this->_example_output($output);       
	}
	
    public function marque(){
	$this->grocery_crud->set_table('marque');
        $output = $this->grocery_crud->render();
	$this->_example_output($output);       
	}
	
    public function theme(){
	$this->grocery_crud->set_table('theme');
        $output = $this->grocery_crud->render();
	$this->_example_output($output);       
	}
	
    public function type_abonnement(){
	$this->grocery_crud->set_table('type_abonnement');
        $output = $this->grocery_crud->render();
	$this->_example_output($output);       
	}
	
    public function type_partenaire(){
	$this->grocery_crud->set_table('type_partenaire');
        $output = $this->grocery_crud->render();
	$this->_example_output($output);       
	}
	
    public function type_privilege(){
	$this->grocery_crud->set_table('type_privilege');
        $output = $this->grocery_crud->render();
	$this->_example_output($output);       
	}
	
    public function type_soin(){
	$this->grocery_crud->set_table('type_soin');
        $output = $this->grocery_crud->render();
	$this->_example_output($output);       
    }
    
    public function users(){
	{
        if (!$this->ion_auth->logged_in())
        {
                redirect('auth', 'refresh');
        }
        else
        {
            redirect('auth/index', 'refresh');
        }
    }       
	}
    public function groups(){
	$this->grocery_crud->set_table('groups');
        $output = $this->grocery_crud->render();
	$this->_example_output($output);       
    }
    function _example_output($output = null)
    {
        if (!$this->ion_auth->logged_in())
        {
                redirect('auth', 'refresh');
        }
        else
        {
            $this->load->view('home.php',$output);
        }
    }    
}
?>